package com.nexgo.payment.action.ecloglist;

import android.support.annotation.NonNull;

import com.nexgo.oaf.apiv3.emv.EmvCardLogEntity;
import com.nexgo.payment.databases.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * 电子现金明细相关操作
 *
 * @author 谭忠扬-YuriTam
 * @time 2017年9月4日
 */
public class EcLogListPresenter implements EcLogListContract.Presenter {
    private Logger mLog = LoggerFactory.getLogger(EcLogListPresenter.class.getSimpleName());

    private EcLogListContract.View mView;
    private DataSource mRepository;

    public EcLogListPresenter(@NonNull EcLogListContract.View view, @NonNull DataSource repository) {
        mView = checkNotNull(view);
        mRepository = checkNotNull(repository);
        view.setPresenter(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void pause() {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void addEcLogList(List<EmvCardLogEntity> logEntityList) {
        if (logEntityList == null || logEntityList.size() == 0) {
            postMainThread(() -> mView.showEmpty());
            return;
        }
        postMainThread(() -> mView.showEcLogList(logEntityList));
    }

    private void postMainThread(Runnable runnable) {
        if (mView.isActive()) {
            runnable.run();
        }
    }
}
